package org.example.controller;

import cn.binarywang.wx.miniapp.api.WxMaService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author shenguangyang
 */
@RestController
public class IndexController {
    @Resource
    private WxMaService wxMaService;

    /**
     * 接入微信公众号回调
     * <a href="https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index">地址</a>
     * 配置接口后点击提交, 微信验证地址是否合法会向配置的地址发送一个get请求
     */
    @GetMapping("/")
    public String configAccess(String signature, String timestamp, String nonce, String echostr) {
        // 校验签名
        if (wxMaService.checkSignature(timestamp, nonce, signature)){
            // 校验成功原样返回 echostr
            return echostr;
        }
        // 校验失败
        return "";
    }

}
